package com.design.pattern.singleton;

public class Singleton {
    //双重锁，非线程安全
    private  static Singleton singleton;

    private Singleton(){
        System.out.println("当前线程:"+Thread.currentThread().getName());
    }

    public static Singleton getInstance(){
        if(singleton == null){  //步骤1
            synchronized (Singleton.class){//同步
                if(singleton == null){//步骤2
                    singleton = new Singleton(); //步骤3
                }
            }
        }
        return singleton;
    }

}
